package com.ettractions.kiosk.commands
{
	import com.ettractions.kiosk.events.SelectBrochureEvent;
	import com.ettractions.kiosk.models.KioskModel;
	import com.ettractions.kiosk.vo.BrochureVO;
	import com.ettractions.kiosk.vo.CategoryVO;
	
	import org.robotlegs.mvcs.Command;

	public class SelectBrochureCommand extends Command
	{
		[Inject]
		public var event:SelectBrochureEvent;
		
		[Inject]
		public var model:KioskModel;
		
		override public function execute():void
		{
			if (event.brochure)
				model.selectedBrochureIndex = model.expandedBrochures.indexOf(event.brochure);
			
			else if (event.indexOffset)
			{
				if (model.selectedBrochureIndex > -1)
				{
					var index:int = model.selectedBrochureIndex + event.indexOffset;
					
					if (index < 0)
						index = model.expandedBrochures.length + index;
						
					else if (index >= model.expandedBrochures.length)
						index = index - model.expandedBrochures.length;
					
					model.selectedBrochureIndex = index;
				}
			}
			
			else if (event.index)
				model.selectedBrochureIndex = event.index;
			
			else
				model.selectedBrochureIndex = -1;
		}
	}
}